#include <stdio.h>                                 
 #include <stdlib.h>
 #include <unistd.h>
   
#define TTY_PATH            "/dev/tty"
#define STTY_US             "stty raw -echo -F "
#define STTY_DEF            "stty -raw echo -F "
  
#define UNUSED_PARAMTER(X)    (void)(X)
  
static char get_char( void )
{
    fd_set rfds;
     struct timeval tv;
     char input_char = 0;

    FD_ZERO(&rfds);
    FD_SET(0, &rfds); 
     /**
    * Set wait time
    */
    //tv.tv_sec = 0;　　　　//seconds
    //tv.tv_usec = 500;　　//microseconds
 
    /*Check for keyboard input.*/
    if (select(1, &rfds, NULL, NULL, &tv) > 0)
         input_char = getchar();
 
     return input_char;
 }
  
 char nonblocking_input( void )
 {
     char input_char;
     
    system(STTY_US TTY_PATH);    //Prohibit echoing，ignoring carriage returns

   // usleep(100);
    input_char = get_char();
 
    system(STTY_DEF TTY_PATH);    //Turn on echo and don't ignore carriage return3 
    return input_char;
 }
  
